package com.zhiyou100.video.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhiyou100.video.ajaxinfo.Data;
import com.zhiyou100.video.ajaxinfo.SeriesData;
import com.zhiyou100.video.ajaxinfo.Title;
import com.zhiyou100.video.model.Course;
import com.zhiyou100.video.service.CourseService;

@Controller
@RequestMapping("/admin")
public class StatisticsController {
	
	@Autowired
	private CourseService cs;

	@RequestMapping("/statistics")
	public String list(String video,String course,String speaker,Model model) {
		return "backstage/statistics/statistics";
	}
	
	@RequestMapping("/data")
	@ResponseBody
	public Map<String, Object> getData(){
		//先创建title
		Title title = new Title();
		title.setText("课程平均播放次数");

		List<Course> list = cs.selectByVideo();
		List<Data> datas = new ArrayList<>();
		for (Course course : list) {
			Data data = new Data();
			data.setName(course.getCourse_name());
			data.setY(course.getAvg());
			datas.add(data);
		}
		
		
		//创建SeriesData对象
		SeriesData sd = new SeriesData();
		sd.setName("课程种类");
		sd.setColorByPoint(true);
		sd.setData(datas);
		List<SeriesData> seriesData = new ArrayList<>();
		seriesData.add(sd);
		
		//把title和seriesData包装到map集合
		Map<String, Object> maps = new HashMap<>();
		maps.put("title", title);
		maps.put("seriesData", seriesData);
		
		return maps;
	}
}
